package cn.jee.jsp;

import cn.jee.jsp.util.JdbcUtil;
import cn.jee.jsp.util.RowProcessor;
import cn.jee.jsp.util.StuRowProcessor;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import cn.jee.jsp.domain.Stu;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;
@WebServlet("/showStus")
public class ShowStusServlet extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req, resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String clazz_id=req.getParameter("clazz_id");
    String sql="select * from stu where clazz_id=?";
    Object[] args={clazz_id};
    List<Stu> stus=JdbcUtil.queryByObj(sql,args, new StuRowProcessor());
    HttpSession session=req.getSession();
    session.setAttribute("stus",stus);
    session.setAttribute("clazz_id",clazz_id);
    resp.sendRedirect(req.getContextPath()+"/stu_list.jsp");
  }


}
